home *** CD-ROM | disk | FTP | other *** search
/ All for Cell Phones: Sony Ericsson / Sony-Ericsson 2004.iso / Java / DateCalc / datum.jar / CalendarCalc.class (.txt) next >
Encoding:
Java Class File  |  2002-11-29  |  3.1 KB  |  75 lines

  1. import java.util.Calendar;
  2.  
  3. public class CalendarCalc {
  4.    private Calendar cal_actual;
  5.    private int year_actual;
  6.    private int month_actual;
  7.    private int day_actual;
  8.    private int hour_actual;
  9.    private int minute_actual;
  10.    private int second_actual;
  11.    private Calendar cal_1;
  12.    private int year_1;
  13.    private int month_1;
  14.    private int day_1;
  15.    private int hour_1;
  16.    private int minute_1;
  17.    private int year_2;
  18.    private int month_2;
  19.    private int day_2;
  20.    private int hour_2;
  21.    private int minute_2;
  22.    private int result_year;
  23.    private long result_month;
  24.    private long result_week;
  25.    private long result_day;
  26.    private long result_hour;
  27.    private long result_minute;
  28.    private long result_second;
  29.    private String[] wochentage = new String[8];
  30.  
  31.    public CalendarCalc(int year1, int month1, int day1, int hour1, int minute1) throws NumberFormatException {
  32.       try {
  33.          this.wochentage[1] = new String("Sonntag");
  34.          this.wochentage[2] = new String("Montag");
  35.          this.wochentage[3] = new String("Dienstag");
  36.          this.wochentage[4] = new String("Mittwoch");
  37.          this.wochentage[5] = new String("Donnerstag");
  38.          this.wochentage[6] = new String("Freitag");
  39.          this.wochentage[7] = new String("Samstag");
  40.          this.year_1 = year1;
  41.          this.month_1 = month1;
  42.          this.day_1 = day1;
  43.          this.hour_1 = hour1;
  44.          this.minute_1 = minute1;
  45.          this.cal_1 = Calendar.getInstance();
  46.          this.cal_1.set(1, this.year_1);
  47.          this.cal_1.set(2, this.month_1 - 1);
  48.          this.cal_1.set(5, this.day_1);
  49.          this.cal_1.set(11, this.hour_1);
  50.          this.cal_1.set(12, this.minute_1);
  51.       } catch (NumberFormatException nfe) {
  52.          throw nfe;
  53.       }
  54.    }
  55.  
  56.    private void calculate() {
  57.       this.cal_actual = Calendar.getInstance();
  58.       this.result_second = Math.abs((this.cal_actual.getTime().getTime() - this.cal_1.getTime().getTime()) / 1000L);
  59.       this.result_minute = this.result_second / 60L;
  60.       this.result_hour = this.result_minute / 60L;
  61.       this.result_day = this.result_hour / 24L;
  62.       this.result_week = this.result_day / 7L;
  63.       this.result_year = Math.abs(this.cal_actual.get(1) - this.year_1);
  64.       this.result_month = (long)Math.abs(12 - this.month_1 + this.month_actual + 11 + (this.result_year - 1) * 12);
  65.    }
  66.  
  67.    public String getResultString() {
  68.       this.calculate();
  69.       new String();
  70.       String nl = new String("\n");
  71.       String result = "Der Abstand zu heute betr├ñgt:" + nl + "in Sekunden: " + nl + this.result_second + nl + "in Minuten: " + nl + this.result_minute + nl + "in Stunden: " + nl + this.result_hour + nl + "in Tagen: " + nl + this.result_day + nl + "in Wochen: " + nl + this.result_week + nl + "in Monaten: " + nl + this.result_month + nl + "in Jahren: " + nl + this.result_year + nl + "Wochentag:" + nl + this.wochentage[this.cal_1.get(7)];
  72.       return result;
  73.    }
  74. }
  75.